package org.afs.gescol.component.edt.gwt.client.view;

import org.afs.gescol.component.edt.gwt.client.factory.EdtComponentClientFactory;
import org.afs.gescol.component.edt.gwt.client.i18n.AppMessages;
import org.afs.gescol.component.edt.gwt.client.presenter.EmploiDuTempsPresenter.EmploiDuTempsView;
import org.scub.foundation.framework.gwt.module.client.util.composants.suggestbox.HasSuggestListBoxHandler;
import org.scub.foundation.framework.gwt.module.client.util.composants.suggestbox.SuggestListBoxSingle;
import org.scub.foundation.framework.gwt.module.client.util.composants.suggestbox.SuggestListBoxSingle.SuggestListBoxSingleProperties;
import org.scub.foundation.framework.gwt.module.shared.IdLabelModel;

import com.bradrydzewski.gwt.calendar.client.Calendar;
import com.github.gwtbootstrap.client.ui.Button;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;

/**
 * Time's table view implementation.
 * @autor Kobla GBENYO (kobla.gbenyo@gmail.com)
 */
public class EmploiDuTempsViewImpl extends Composite implements EmploiDuTempsView {

    private AppMessages messages = EdtComponentClientFactory.getMessages();

    private EmploiDuTempsViewBinder binder = EdtComponentClientFactory.getEmploiDuTempsViewBinder();

    @UiField Calendar edt;
    @UiField Button precButton;
    @UiField Button courButton;
    @UiField Button suivButton;
    @UiField Button printButton;
    @UiField(provided = true)
    SuggestListBoxSingle<IdLabelModel> slbClasse;

    /**
     * An interface required by the UiBinder.
     */
    public interface EmploiDuTempsViewBinder extends UiBinder<Widget, EmploiDuTempsViewImpl> {
    }

    @Override
    public void init() {
        slbClasse = new SuggestListBoxSingle<IdLabelModel>(new SuggestListBoxSingleProperties<IdLabelModel>() {
            @Override
            public String getSelectSuggestRenderer(IdLabelModel row) {
                return row != null && row.getLabel() != null ? row.getLabel() : "";
            }
            @Override
            public String[] getResultColumnsRenderer() {
                return new String[] {messages.lblLibelle()};
            }
            @Override
            public String[] getResultRowsRenderer(IdLabelModel row) {
                return new String[] {row != null && row.getLabel() != null ? row.getLabel() : ""};
            }
        });
        slbClasse.setWidth(AppMessages.PIXELS_50);
        initWidget(binder.createAndBindUi(this));
    }

    @Override
    public Widget asWidget() {
        return this;
    }

    @Override
    public IsWidget getPrincipalContainer() {
        return getWidget();
    }

    @Override
    public Calendar getEdt() {
        return edt;
    }

    @Override
    public HasClickHandlers getSuivant() {
        return suivButton;
    }

    @Override
    public HasClickHandlers getPrecedent() {
        return precButton;
    }

    @Override
    public HasClickHandlers getCourant() {
        return courButton;
    }

    @Override
    public HasSuggestListBoxHandler<IdLabelModel> getClassSuggestHandler() {
        return slbClasse;
    }

    @Override
    public HasValue<IdLabelModel> getClassValue() {
        return slbClasse;
    }

    @Override
    public HasClickHandlers getPrintClickHandlers() {
        return printButton;
    }

}
